home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / source.test < prev    next >
Text File  |  1992-11-06  |  3KB  |  85 lines

  1. # Commands covered:  source
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /sprite/src/lib/tcl/tests/RCS/source.test,v 1.6 91/09/11 17:30:17 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test source-1.1 {source command} {
  21.     set x "old x value"
  22.     set y "old y value"
  23.     set z "old z value"
  24.     exec cat << {
  25.     set x 22
  26.     set y 33
  27.     set z 44
  28.     } > source.file
  29.     source source.file
  30.     list $x $y $z
  31. } {22 33 44}
  32. test source-1.2 {source command} {
  33.     exec cat << {list result} > source.file
  34.     source source.file
  35. } result
  36.  
  37. test source-2.1 {source error conditions} {
  38.     list [catch {source} msg] $msg
  39. } {1 {wrong # args: should be "source fileName"}}
  40. test source-2.2 {source error conditions} {
  41.     list [catch {source a b} msg] $msg
  42. } {1 {wrong # args: should be "source fileName"}}
  43. test source-2.3 {source error conditions} {
  44.     exec cat << {
  45.     set x 146
  46.     error "error in sourced file"
  47.     set y $x
  48.     } > source.file
  49.     list [catch {source source.file} msg] $msg $errorInfo
  50. } {1 {error in sourced file} {error in sourced file
  51.     while executing
  52. "error "error in sourced file""
  53.     (file "source.file" line 3)
  54.     invoked from within
  55. "source source.file"}}
  56. test source-2.4 {source error conditions} {
  57.     exec cat << {break} > source.file
  58.     catch {source source.file}
  59. } 3
  60. test source-2.5 {source error conditions} {
  61.     exec cat << {continue} > source.file
  62.     catch {source source.file}
  63. } 4
  64. test source-2.6 {source error conditions} {
  65.     string tolower [list [catch {source _non_existent_} msg] $msg $errorCode]
  66. } {1 {couldn't read file "_non_existent_": no such file or directory} {unix enoent {no such file or directory}}}
  67.  
  68. test source-3.1 {return in middle of source file} {
  69.     exec cat << {
  70.     set x new-x
  71.     return allDone
  72.     set y new-y
  73.     } > source.file
  74.     set x old-x
  75.     set y old-y
  76.     set z [source source.file]
  77.     list $x $y $z
  78. } {new-x old-y allDone}
  79.  
  80. catch {exec rm source.file}
  81.  
  82. # Generate null final value
  83.  
  84. concat {}
  85.